//
//  OrderSubmitErrorViewController.m
//  OMS
//
//  Created by goldeney on 14-10-11.
//  Copyright (c) 2014年 ShangHai Goldeneye Techonology Co.,Ltd. All rights reserved.
//

#import "OMOrderSubmitErrorViewController.h"

@interface OMOrderSubmitErrorViewController ()

@property (nonatomic,strong) NSString *message;
@property (nonatomic,assign) BOOL isModification;

@end

@implementation OMOrderSubmitErrorViewController

- (id)initWithMayModification:(NSString*)message
{
    self = [super init];
    if (self) {
        self.message = message;
        self.isModification = YES;
    }
    return self;
}

-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        [self setTitle: @"订单提交结果"];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    if (self.isModification) {
        self.messageLable.text = [NSString stringWithFormat:@"%@",self.message];
        [self.messageButton setTitle:@"修改订单" forState:UIControlStateNormal];
    } else {
        self.messageLable.text = @"1、网络连接不通畅，请检查网络连接是否正常。\r\n2、无权限提交订单，请联系相关人员开通服务。\r\n3、合同不可用，可能是合同未审核或停用。";
        [self.messageButton setTitle:@"重新提交" forState:UIControlStateNormal];
    }
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.extendedLayoutIncludesOpaqueBars = NO;
    self.edgesForExtendedLayout = UIRectEdgeBottom | UIRectEdgeLeft | UIRectEdgeRight;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -
#pragma mark IBAction Event

- (IBAction)submitOrderButtonEvent:(id)sender
{
    //关闭页面
    MainAppDelegate *mDelegate = (MainAppDelegate*)[[UIApplication sharedApplication] delegate];
    if (!self.isModification) {
        //重新提交订单
        [mDelegate.navigationController popViewControllerAnimated:YES];
        if (self.backResultDelagate && [self.backResultDelagate respondsToSelector:@selector(backResultDataKey:dataValue:)])
        [self.backResultDelagate backResultDataKey:self.key dataValue:nil];
    } else {
        //退到订单修改
        NSArray *viewControllers = mDelegate.navigationController.viewControllers;
        UIViewController *closeController = [viewControllers objectAtIndex:viewControllers.count - 3];
        [mDelegate.navigationController popToViewController:closeController animated:YES];
    }
    
}

- (void)backButtonEvent:(id)sender
{
    MainAppDelegate *mDelegate = (MainAppDelegate*)[[UIApplication sharedApplication] delegate];
    NSArray *viewControllers = mDelegate.navigationController.viewControllers;
    UIViewController *closeController = [viewControllers objectAtIndex:viewControllers.count - 3];
    [mDelegate.navigationController popToViewController:closeController animated:YES];
}

@end
